package com.testmanager.testmananger.shuiyou.szjk.repository;

import com.querydsl.core.types.dsl.BooleanExpression;

import com.testmanager.testmananger.shuiyou.szjk.domain.ChangeRecordEntity;
import com.testmanager.testmananger.shuiyou.szjk.domain.QChangeRecordEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@Transactional(readOnly =  true)
public class ChangeRecordCustom {

    @Autowired
    ChangeRecordRepository changeRecordRepository;

    public Page<ChangeRecordEntity> getPages(){

              QChangeRecordEntity  qChangeRecordEntity = QChangeRecordEntity.changeRecordEntity;
              BooleanExpression expression = qChangeRecordEntity.id.isNotNull();
              Sort orders = Sort.by(Sort.Order.asc(qChangeRecordEntity.id.getMetadata().getName()),
                                Sort.Order.desc(qChangeRecordEntity.id.getMetadata().getName()));
              Pageable pageable = PageRequest.of(0, 30,orders);
              return changeRecordRepository.findAll(expression, pageable);
          }

    /**
     *  public Page<IterationInfoEntity>  search(IterationSearchDto iterationSearchDto){
     *         QIterationInfoEntity qIterationInfoEntity=QIterationInfoEntity.iterationInfoEntity;
     *         BooleanExpression expression = qIterationInfoEntity.id.isNotNull();
     *         if (!iterationSearchDto.getStatus() .equals(IteraSearchStatus.ALL) && !iterationSearchDto.getStatus().equals(IteraSearchStatus.UNComplete)  ){
     *             expression = expression.and(qIterationInfoEntity.status.eq(IterationStatus.getValueOf(iterationSearchDto.getStatus().getValue()) ));
     *         }else if(iterationSearchDto.getStatus().equals(IteraSearchStatus.UNComplete) ){
     *             expression=expression.and(qIterationInfoEntity.status.in(IterationStatus.WAITDEVELOPER,IterationStatus.WAITREVIEW,
     *                     IterationStatus.DEVELOPING,IterationStatus.WAITTESTER,IterationStatus.TESTING,IterationStatus.WAITONLINE));
     *         }
     *
     *         Sort orders = Sort.by(Sort.Order.asc(qIterationInfoEntity.status.getMetadata().getName()),
     *                 Sort.Order.desc(qIterationInfoEntity.createdDate.getMetadata().getName()));
     *         Pageable pageable = PageRequest.of(iterationSearchDto.getPagenum(), iterationSearchDto.getSize(),orders);
     *        // Iterable<IterationInfoEntity> xx = iterationInfoRepository.findAll(expression);
     *
     *         return iterationInfoRepository.findAll(expression, pageable);
     *     }
     *
     *     public Page<IterationInfoEntity>  getPages(){
     *         QIterationInfoEntity qIterationInfoEntity=QIterationInfoEntity.iterationInfoEntity;
     *         BooleanExpression expression = qIterationInfoEntity.id.isNotNull();
     *         Sort orders = Sort.by(Sort.Order.asc(qIterationInfoEntity.status.getMetadata().getName()),
     *                 Sort.Order.desc(qIterationInfoEntity.createdDate.getMetadata().getName()));
     *         Pageable pageable = PageRequest.of(0, 30,orders);
     *         return iterationInfoRepository.findAll(expression, pageable);
     *     }
     */
}
